﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Eneta.Portal.Common.Repository;
using Microsoft.SharePoint;

namespace Eneta.Portal.Admin.Controls
{
    public class AdminCompanyListControl : UserControl
    {
        protected Repeater _companiesRepeater;
        protected Label _noCompaniesLabel;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var repository = new CompanyRepository(SPContext.Current.Web);
            var blogs = repository.GetPendingCompanies();

            _companiesRepeater.Visible = false;
            _noCompaniesLabel.Visible = false;

            if (blogs != null && blogs.Count > 0)
            {
                _companiesRepeater.DataSource = blogs;
                _companiesRepeater.DataBind();
                _companiesRepeater.Visible = true;
            }
            else
            {
                _noCompaniesLabel.Visible = true;
            }
        }
    }
}
